﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Threading.Tasks;
using System.Net;
using System.Web;
using System.Web.Mvc;
using LanDBom.Models;
using MathNet.Numerics.Distributions;
using OfficeOpenXml;
using System.IO;
using Microsoft.Office.Interop.Excel;
using Newtonsoft.Json;
using NPOI.SS.Formula.Functions;
using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder;
using static System.Windows.Forms.AxHost;

namespace LanDBom.Controllers
{
    public class LanJiLusController : Controller
    {
        private LDbaseEntities db = new LDbaseEntities();

        // GET: LanJiLus
        public ActionResult Index(string ming = "")
        {
            var parice = db.LanJiLu.ToList();
                parice = parice.Where(s => s.JL_Name.Contains(ming)).ToList();
            return View(parice);
        }

        // GET: LanJiLus/Details/5
        public async Task<ActionResult> Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            LanJiLu lanJiLu = await db.LanJiLu.FindAsync(id);
            if (lanJiLu == null)
            {
                return HttpNotFound();
            }
            return View(lanJiLu);
        }

        // GET: LanJiLus/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: LanJiLus/Create
        // 为了防止“过多发布”攻击，请启用要绑定到的特定属性；有关
        // 更多详细信息，请参阅 https://go.microsoft.com/fwlink/?LinkId=317598。
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Create([Bind(Include = "JL_ID,JL_Name,JL_Fen,JL_Time,JL_Price")] LanJiLu lanJiLu)
        {
            if (ModelState.IsValid)
            {
                db.LanJiLu.Add(lanJiLu);
                await db.SaveChangesAsync();
                return RedirectToAction("Index");
            }

            return View(lanJiLu);
        }

        // GET: LanJiLus/Edit/5
        public async Task<ActionResult> Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            LanJiLu lanJiLu = await db.LanJiLu.FindAsync(id);
            if (lanJiLu == null)
            {
                return HttpNotFound();
            }
            return View(lanJiLu);
        }

        // POST: LanJiLus/Edit/5
        // 为了防止“过多发布”攻击，请启用要绑定到的特定属性；有关
        // 更多详细信息，请参阅 https://go.microsoft.com/fwlink/?LinkId=317598。
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Edit([Bind(Include = "JL_ID,JL_Name,JL_Fen,JL_Time,JL_Price")] LanJiLu lanJiLu)
        {
            if (ModelState.IsValid)
            {
                db.Entry(lanJiLu).State = EntityState.Modified;
                await db.SaveChangesAsync();
                return RedirectToAction("Index");
            }
            return View(lanJiLu);
        }

        // GET: LanJiLus/Delete/5
        public async Task<ActionResult> Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            LanJiLu lanJiLu = await db.LanJiLu.FindAsync(id);
            if (lanJiLu == null)
            {
                return HttpNotFound();
            }
            return View(lanJiLu);
        }

        // POST: LanJiLus/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> DeleteConfirmed(int id)
        {
            LanJiLu lanJiLu = await db.LanJiLu.FindAsync(id);
            db.LanJiLu.Remove(lanJiLu);
            await db.SaveChangesAsync();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }

        

       
    }
}
